<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 19/12/21
 * Time: 19:20
 */

namespace app\store\controller;


use app\common\bean\GlobalBean;
use app\common\bean\ListMap;
use app\common\bean\OrderGoodsBean;
use app\common\controller\StoreController;
use app\common\enum\OrderGoodsPayTypeEnum;
use app\common\enum\OrderGoodsStatusEnum;
use app\common\enum\OrderGoodsTypeEnum;
use app\common\manage\OrderGoodsManage;
use app\common\model\OrderGoodsModel;
use app\common\utils\ExitJsonUtil;

class OrderGoods extends StoreController
{
    public function edit(){
        $order = OrderGoodsModel::getInstance()->selectData([OrderGoodsBean::$id=>$this->postParams['id']]);
        if(session(GlobalBean::$storeId)==$order[OrderGoodsBean::$storeId]){
            $orderGoodsBean = new OrderGoodsBean();
            $orderGoodsBean->setData($this->postParams);
            $orderGoodsBean->setStatus(OrderGoodsStatusEnum::HADCOMFIRM);
            OrderGoodsManage::getInstance()->edit($orderGoodsBean);
            ExitJsonUtil::getInstance()->exitData([]);
        }
    }
    public function downloadImg(){
        $OrderGoodsBean = new OrderGoodsBean();
        $OrderGoodsBean->setData($this->getParams);
        $orderGoodsBean = OrderGoodsManage::getInstance()->getInfo($OrderGoodsBean);

        $localurl = OrderGoodsManage::getInstance()->downZip($orderGoodsBean, $this->getParams['start']);
        header("Location:{$localurl}");
    }
    public function index(){//商品订单
        $listMap = new ListMap();
        $listMap->setData($this->getParams);
        $listMap->setParameter(OrderGoodsBean::$storeId, session(GlobalBean::$storeId));
        $orderListMap = OrderGoodsManage::getInstance()->getPaginatorList($listMap);

        $this->assign([
            'orderList'=>$orderListMap->getList(),
            'currentPage'=>$orderListMap->getCurrentPage(),
            'totalCount'=>$orderListMap->getTotalCount(),
            'statusSelect'=>OrderGoodsStatusEnum::getArrayName(),
            'statusPay'=>OrderGoodsPayTypeEnum::getArrayName(),
        ]);
        return $this->fetch();
    }
    public function info(){
        $orderGoodsBean = new OrderGoodsBean();
        $orderGoodsBean->setData($this->getParams);
        $orderGoodsBean->setParameter(OrderGoodsBean::$storeId, session(GlobalBean::$storeId));
        $sarr = OrderGoodsManage::getInstance()->getSplit($this->getParams['id']);
        $orderGoodsBean = OrderGoodsManage::getInstance()->getInfo( $orderGoodsBean );
        $this->assign([
            'orderGoods'=>$orderGoodsBean->getData(),
            'ogt'=>OrderGoodsTypeEnum::getArrayName(),
            'ogs'=>OrderGoodsStatusEnum::getArrayName(),
            'ogp'=>OrderGoodsPayTypeEnum::getArrayName(),
            'detail'=>OrderGoodsManage::getInstance()->detail($orderGoodsBean),
            'sarr'=>$sarr
        ]);
        return $this->fetch();
    }
}